﻿using System.Web;
using PaceR.Core.EntityStorage;


namespace PaceR.Web.EntityStorage
{
    /// <summary>
    /// Stores objects in Session
    /// </summary>
    public sealed class SessionStorage : EntityStore
    {
        /// <summary>
        /// Get a stored entity
        /// </summary>
        /// <param name="storageKey"></param>
        /// <returns></returns>
        protected override object GetEntity(string storageKey)
        {
            return HttpContext.Current.Session[storageKey];
        }
        /// <summary>
        /// Save an entity
        /// </summary>
        /// <param name="storageKey"></param>
        /// <param name="entity"></param>
        protected override void SaveEntity(string storageKey, object entity)
        {
            HttpContext.Current.Session[storageKey] = entity;
        }
        /// <summary>
        /// Clear a saved entity
        /// </summary>
        /// <param name="storageKey"></param>
        protected override void ClearEntity(string storageKey)
        {
            HttpContext.Current.Session.Remove(storageKey);
        }
    }
}
